//
//  BaeTableViewController.swift
//  MyBlog
//
//  Created by lvtienan on 15/7/28.
//  Copyright © 2015年 ltn. All rights reserved.
//

import UIKit

class BaeTableViewController: UITableViewController, VisitoeLoginViewDelegate{
    
    /**
    *  用户登录标记
    */
    // var userLogon = UserAccount.loadAccount() != nil
    var userLogon = UserAccount.userLogin
    
    // 访客视图
    var visitorView: VisitorLoginView?
    
    override func loadView() {
        // 根据用户登录判断是否显示根试图
        print("userLogon---\(userLogon)")
        userLogon ? super.loadView() : setupVisitorView()
    }
    
    ///设置访客视图
    private func setupVisitorView() {
        visitorView = VisitorLoginView()
        visitorView?.delegate = self
        view = visitorView
        // 设置状态栏
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorLoginViewWillRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorLoginViewWillLogin")
    }
    
    /// MARK - VisitorLoginViewDelegate
    func visitorLoginViewWillRegister() {
        print("注册")
    }
    
    func visitorLoginViewWillLogin() {
        // 利用 modal 的方式,弹出登录的界面
         let av = UINavigationController(rootViewController: OAuthViewController())
         presentViewController(av, animated: true, completion: nil)
    }
    
    
    
}
